{// 引入标签库 }
<tagLib name="fanwe" />
{// 加载头部公共文件 }
<include file="Public:header" />
<script type="text/javascript" src="__TMPL__ThemeFiles/Js/calendar.php?lang=zh-cn" ></script>
<load href='__TMPL__ThemeFiles/Js/calendar/calendar.css' />
<load href="__TMPL__ThemeFiles/Js/jquery.js" />
<load href="__TMPL__ThemeFiles/Js/jquery.json.js" />
<load href='__TMPL__ThemeFiles/Css/jqModal.css' />
<load href='__TMPL__ThemeFiles/Js/jqModal.js' />
<!-- 菜单区域  -->

<!-- 主页面开始 -->
<div id="main" class="main" >

<!-- 主体内容  -->
<div class="content" >
<div class="title">{$Think.lang.DATA_LIST}</div>

<SCRIPT LANGUAGE="JavaScript">
function cancelList(){
	if ('{$vo.is_card}' == '1'){
		location.href = "{:u('Promote/promoteCard')}";
	}else{
		//alert("{:u('Promote/promoteModule')}");
		location.href =  "{:u('Promote/promoteModule')}";
	}
}

 function newTr(module_name,rec_id, name, score) {
	 
     var html = '<tr class="row" onmouseover="over(event)" onmouseout="out(event)"  id="tr'+rec_id+'">';

     html += '<td><input type="checkbox" name="key" value="'+rec_id+'"><input type="hidden" name="module_nameList[]" value="'+module_name+'"><input type="hidden" name="rec_idList[]" value="'+rec_id+'"></td>';
     
     html += '<td>' + rec_id + '</td>';
     
     if ({$vo.promote_type_id} == 8){
    	 html += '<td>' + name + '</td>';
    	 html += '<td><input type="text" name="scoreList[]" value="'+score+'"></td>';
     }else{
    	 html += '<td>' + name + '<input type="hidden" name="scoreList[]" value="'+score+'"></td>';
     }

     html += '<td><a href="javascript:delItem(\'' + rec_id+'\')">{$Think.lang.DELETE}</a></td>';

     html += '</tr>';
	//alert(html);
     $('#promoteChild').append(html);
}
 
 function delItem(id) {
 	$('#tr' + id).remove();
 }
 
function delItems() {
	var obj = document.getElementsByName('key');
	for (var i = obj.length - 1; i >= 0; i--)
	{
		if (obj[i].checked == true){
			delItem(obj[i].value);
		}
	}	
}

function postForm(){
	document.getElementById('form1').submit();
	return true;
}

</SCRIPT>

<FORM METHOD=POST id="form1" action="{:u('Promote/save')}">
<TABLE cellpadding=3 cellspacing=3>
	
	<switch name="vo.is_card">
	<case value="1">
		<TR class="row">
			<th class="tCenter space" colspan=2>{$Think.lang.PROMOTE_CARD_SET}</th>
		</TR>
		<TR>
			<TD class="tRight">{$Think.lang.PROMOTE_CARD_NAME}：</TD>
			<TD class="tLeft">
				<fanwe:textbox_n name="card_name" id="card_name"  class="bLeft" dataSource = "vo.card_name"/>
			</TD>
		</TR>	
		<TR>
			<TD class="tRight">{$Think.lang.PROMOTE_CARD_SCORE}：</TD>
			<TD class="tLeft">
				<INPUT TYPE="text" class="medium bLeftRequire" NAME="card_score" value="{$vo.card_score}">
			</TD>
		</TR>	
		<TR>
			<TD class="tRight">{$Think.lang.PROMOTE_CARD_LIMIT}：</TD>
			<TD class="tLeft">
				<INPUT TYPE="text" class="medium bLeftRequire" NAME="card_limit" value="{$vo.card_limit}">
			</TD>
		</TR>				
	</case>
	</switch>
		
	<TR class="row">
		<th class="tCenter space"  colspan=2>{$vo.promote_type_id}:
			<if condition="$vo.promote_type_id eq 1 "> 
			{$Think.lang.PROMOTE_PROMOTE_TYPE_ID_1}
			<elseif condition="$vo.promote_type_id eq 2" />
			{$Think.lang.PROMOTE_PROMOTE_TYPE_ID_2}
			<elseif condition="$vo.promote_type_id eq 3" />
			{$Think.lang.PROMOTE_PROMOTE_TYPE_ID_3}
			<elseif condition="$vo.promote_type_id eq 4" />
			{$Think.lang.PROMOTE_PROMOTE_TYPE_ID_4}
			<elseif condition="$vo.promote_type_id eq 5" />
			{$Think.lang.PROMOTE_PROMOTE_TYPE_ID_5}
			<elseif condition="$vo.promote_type_id eq 6" />
			{$Think.lang.PROMOTE_PROMOTE_TYPE_ID_6}
			<elseif condition="$vo.promote_type_id eq 7" />
			{$Think.lang.PROMOTE_PROMOTE_TYPE_ID_7}
			<elseif condition="$vo.promote_type_id eq 8" />
			{$Think.lang.PROMOTE_PROMOTE_TYPE_ID_8}			
			</if>			
		</th>	
	</TR>
	<TR class="row">
		<th class="tCenter space">{$Think.lang.PROMOTE_TITEL1}：</th>
	</TR>
	<switch name="vo.promote_type_id">
	<case value="1|4|5|6|7">	
		<TR>
			<TD class="tRight">{$Think.lang.PROMOTE_CONDITION}：</TD>
			<TD class="tLeft">
				<INPUT TYPE="text" class="medium bLeftRequire" NAME="order_price_min" value="{$vo.order_price_min}">≤{$Think.lang.PROMOTE_MONEY}＜ 
				<INPUT TYPE="text" class="medium bLeftRequire" NAME="order_price_max" value="{$vo.order_price_max}">
			</TD>
		</TR>
	</case>
	</switch>
	
	<TR>
		<TD class="tRight">{$Think.lang.PROMOTE_USER_GROUP}：</TD>
		<TD class="tLeft">
			<iterate name="userGroupList" id="mrlist">
				<label><INPUT TYPE="checkbox" NAME="user_group_id[]" id="user_group_id_{$mrlist.id}" value ="{$mrlist.id}"  >{$mrlist.id}-{$mrlist.name}</label>&nbsp;&nbsp;&nbsp;&nbsp;  
			</iterate>
		</TD>
	</TR>
	
	<switch name="vo.promote_type_id">
	<case value="1|2|3|4|5|6|7">
	<TR>
		<TD class="tRight">{$Think.lang.PROMOTE_PRIORITY2}：</TD>
		<TD class="tLeft">
		   <INPUT class="medium bLeft" TYPE="text" name="priority" value="{$vo.priority}">
		</TD>
	</TR>
	</case>
	</switch>
	
	<TR class="row">
		<th class="tCenter space">{$Think.lang.PROMOTE_TITEL2}：</th>
	</TR>

	<TR>
		<TD class="tRight">{$Think.lang.STATUS}：</TD>
		<TD class="tLeft">
			<label>
				<INPUT TYPE="radio" name="status" value="1"<if condition="$vo.status eq 1"> checked</if> >{$Think.lang.PROMOTE_STATUS_1}
			</label>
			<label>
			 	<INPUT TYPE="radio" name="status" value="0"<if condition="$vo.status eq 0">checked</if> >{$Think.lang.PROMOTE_STATUS_0}
			</label>
		</TD>
	</TR>
	
	<switch name="vo.is_card">
	<case value="0">
		<switch name="vo.promote_type_id">
		<case value="1|2|3|4|5|6|7">	
			<TR>
				<TD class="tRight">{$Think.lang.PROMOTE_USE_CARD}：</TD>
				<TD class="tLeft">
					<label>
						<INPUT TYPE="radio" name="use_card" value="1"<if condition="$vo.use_card eq 1"> checked</if> >{$Think.lang.YES}
					</label>
					<label>
					 	<INPUT TYPE="radio" name="use_card" value="0"<if condition="$vo.use_card eq 0">checked</if> >{$Think.lang.NO}
					</label>
				</TD>
			</TR>
		</case>
		</switch>			
	</case>
	<case value="1">
		<INPUT TYPE="hidden" name="use_card" value="1" >
	</case>
	</switch>

	<TR>
		<TD class="tRight">{$Think.lang.PROMOTE_BEGIN_TIME}：</TD>
		<TD class="tLeft">
			<INPUT TYPE="text" class="medium bLeft" NAME="promote_begin_time" id="promote_begin_time" value="{$vo.promote_begin_time}" size="12">
			<input name="selbtn1" type="button" id="selbtn1" onclick="return showCalendar('promote_begin_time', '%Y-%m-%d', false, false, 'selbtn1');" value="{$Think.lang.SELECT}" class="button" />
		</TD>
	</TR>
	<TR>
		<TD class="tRight">{$Think.lang.PROMOTE_END_TIME}：</TD>
		<TD class="tLeft">
			<INPUT TYPE="text" class="medium bLeft"	NAME="promote_end_time" id="promote_end_time" value="{$vo.promote_end_time}" size="12">
			<input name="selbtn2" type="button" id="selbtn2" onclick="return showCalendar('promote_end_time', '%Y-%m-%d', false, false, 'selbtn2');" value="{$Think.lang.SELECT}" class="button" />
		</TD>
	</TR>
	
	<switch name="vo.promote_type_id">
	<case value="1">	
		<TR class="row">
			<th class="tCenter space">{$Think.lang.PROMOTE_TITEL3}：</th>
		</TR>
		<TR>
			<TD class="tLeft" colspan=2>
			<table id="promoteChild" class="list" cellpadding=0 cellspacing=0>
				<tr>
					<td height="5" colspan="4" class="topTd"></td>
				</tr>
				<tr class="row">
					<th width="8"><input type="checkbox" id="check"	onclick="CheckAll('promoteChild')"></th>
					<th width="100"><a id="addChild" href="#"  title="{$Think.lang.PROMOTE_TITEL7}">{$Think.lang.PROMOTE_TITEL4}</a></th>
					<th>{$Think.lang.PROMOTE_LARGESS_NAME}</th>
					<th width="100"><a href="javascript:delItems()" title="{$Think.lang.PROMOTE_TITEL8}">{$Think.lang.PROMOTE_TITEL5}</a></th>
				</tr>
			</table>
		</TR>
	</case>
	<case value="2|3">
		<if condition="$vo.promote_type_id eq 2 ">
			<TR class="row">
				<th class="tCenter space">{$Think.lang.PROMOTE_TITEL13}：</th>
			</TR>		
			<TR class="row">
				<TD class="tRight">{$Think.lang.PROMOTE_INPUT_DISCOUNT_RADIO}：</TD>
				<TD class="tLeft"><INPUT class="medium bLeft" TYPE="text" name="discount_radio" value="{$vo.discount_radio}">  {$Think.lang.PROMOTE_DISCOUNT_RADIO_DEMO}；</TD>
			</TR>
		<elseif condition="$vo.promote_type_id eq 3" />	
			<TR class="row">
				<th class="tCenter space">{$Think.lang.PROMOTE_TITEL13}：</th>
			</TR>		
			<TR class="row">
				<TD class="tRight">{$Think.lang.PROMOTE_SCORE_RADIO}：</TD>
				<TD class="tLeft"><INPUT class="medium bLeft" TYPE="text" name="discount_radio" value="{$vo.discount_radio}"> {$Think.lang.PROMOTE_SCORE_RADIO_DEMO}；</TD>
			</TR>		
		</if>
		
		<TR class="row">
			<th class="tCenter space">{$Think.lang.PROMOTE_TITEL14}：</th>	
		</TR>
		<TR>
			<TD class="tLeft" colspan=2>
				<table id="promoteChild" class="list" cellpadding=0 cellspacing=0>
					<tr>
						<td height="5" colspan="7" class="topTd"></td>
					</tr>
					<tr class="row">
						<th width="8"><input type="checkbox" id="check"	onclick="CheckAll('promoteChild')"></th>
						<th width="100"><a id="addChild" href="#"  title="{$Think.lang.PROMOTE_TITEL9}">{$Think.lang.PROMOTE_TITEL4}</a></th>
						<th>{$Think.lang.PROMOTE_GOODS_NAME}</th>
						<th width="100"><a href="javascript:delItems()" title="{$Think.lang.PROMOTE_TITEL10}">{$Think.lang.PROMOTE_TITEL5}</a></th>
					</tr>
				</table>
			</TD>	
		</TR>	
	</case>
	<case value="4">	
		<TR class="row">
			<th class="tCenter space">{$Think.lang.PROMOTE_TITEL13}：</th>
		</TR>	
		
		<TR class="row">
			<TD class="tRight">{$Think.lang.PROMOTE_TITEL15}：</TD>
			<TD class="tLeft"><label>{$Think.lang.PROMOTE_DILIVERY_FREE}&nbsp;<INPUT TYPE="checkbox" name="dilivery_free" checked disabled ></label>
			
			</TD>
		</TR>
	</case>
	<case value="5">	
		<TR class="row">
			<th class="tCenter space">{$Think.lang.PROMOTE_TITEL6}：</th>
		</TR>
		<TR>
			<TD class="tLeft" colspan=2>
			<table id="promoteChild" class="list" cellpadding=0 cellspacing=0>
				<tr>
					<td height="5" colspan="4" class="topTd"></td>
				</tr>
				<tr class="row">
					<th width="8"><input type="checkbox" id="check"	onclick="CheckAll('promoteChild')"></th>
					<th width="100"><a id="addChild" href="#" title="{$Think.lang.PROMOTE_TITEL11}">{$Think.lang.PROMOTE_TITEL4}</a></th>
					<th>{$Think.lang.PROMOTE_CARD_NAME}</th>
					<th width="100"><a href="javascript:delItems()" title="{$Think.lang.PROMOTE_TITEL12}">{$Think.lang.PROMOTE_TITEL5}</a></th>
				</tr>
			</table>
		</TR>
	</case>		
	<case value="6|7">
		<TR class="row">
			<th class="tCenter space">{$Think.lang.PROMOTE_TITEL13}：</th>
		</TR>
		<if condition="$vo.promote_type_id eq 6 ">
			<TR class="row">
				<TD class="tRight">{$Think.lang.PROMOTE_INPUT_DISCOUNT_RADIO}：</TD>
				<TD class="tLeft"><INPUT class="medium bLeft" TYPE="text" name="discount_radio" value="{$vo.discount_radio}">  {$Think.lang.PROMOTE_DISCOUNT_RADIO_DEMO}；</TD>
			</TR>
		<elseif condition="$vo.promote_type_id eq 7" />	
			<TR class="row">
				<TD class="tRight">{$Think.lang.PROMOTE_DEC_MONEY}：</TD>
				<TD class="tLeft"><INPUT class="medium bLeft" TYPE="text" name="discount_radio" value="{$vo.discount_radio}"> {$Think.lang.PROMOTE_DEC_MONEY_DEMO}；</TD>
			</TR>		
		</if>
	</case>
	<case value="8">	
		<TR class="row">
			<th class="tCenter space">{$Think.lang.PROMOTE_TITEL17}：</th>
		</TR>
		<TR>
			<TD class="tLeft" colspan=2>
			<table id="promoteChild" class="list" cellpadding=0 cellspacing=0>
				<tr>
					<td height="5" colspan="5" class="topTd"></td>
				</tr>
				<tr class="row">
					<th width="8"><input type="checkbox" id="check"	onclick="CheckAll('promoteChild')"></th>
					<th width="100"><a id="addChild" href="#"  title="{$Think.lang.PROMOTE_TITEL7}">{$Think.lang.PROMOTE_TITEL4}</a></th>
					<th>{$Think.lang.PROMOTE_TITEL17}</th>
					<th>{$Think.lang.PROMOTE_TITEL18}</th>
					<th width="100"><a href="javascript:delItems()" title="{$Think.lang.PROMOTE_TITEL8}">{$Think.lang.PROMOTE_TITEL5}</a></th>
				</tr>
			</table>
		</TR>
	</case>		
	</switch>
	
	<TR class="row">
		<th class="tCenter space">{$Think.lang.PROMOTE_TITEL16}：</th>
	</TR>
		
	<TR>
		<TD class="tLeft" colspan="2" >
			<fanwe:textarea_n name="memo" class="bLeft" cols="100" rows="5" dataSource = "vo.memo"/>
		</TD>
	</TR>

	<TR>
		<TD></TD>
		<TD class="center">
			<INPUT TYPE="hidden" name="id" value="{$vo.id}"> 
			<INPUT TYPE="hidden" name="is_card" value="{$vo.is_card}" >
			<INPUT TYPE="hidden" name="promote_type_id" value="{$vo.promote_type_id}"> 
			
			<switch name="vo.id">
			<case value="0">			
				<INPUT TYPE="button" class="button" value="{$Think.lang.LAST_SET}" onclick="javascript:history.back(1)" /> 
			</case>		
			</switch>
				
			<INPUT TYPE="button" value="{$Think.lang.SAVE_DATA}"  class="button" onclick="javascript:postForm()">
			<INPUT TYPE="button" class="submit  small" value="{$Think.lang.CANCEL}" onclick="javascript:cancelList()">
		</TD>
	</TR>
</TABLE>
</FORM>
</div>
</div>

<if condition="$module_name neq '' ">
	<div id="selectbox" class="jqmDialog jqmWindow">
	<div class="jqmdTC">{$Think.lang.PROMOTE_PLEASE_CHOOSE}</div>
	<div class="jqmdBL"><div class="jqmdBR"><div class="jqmdBC">
	
	<div class="jqmdMSG">
	<iframe src="{:u("$module_name/search",array('ajax'=>2))}" width="600" height="300" frameborder="0" scrolling="no" id="if_goods_list" style="overflow-y:auto;"></iframe>
	</div>
	
	</div></div></div>
	<input type="hidden" value="1" id="is_close" />
	<input type="button" value="{%CLOSE}" class="jqmdX jqmClose" onclick="$('#is_close').val(0);"/>
	<input type="button" value="{%SELECT}" class="jqmdX jqmClose" />
	</div>
</if>

<script type="text/javascript">

function getElementByIdInIFrame(objIFrame, idInIFrame)
{
    var obj;
    if (objIFrame.contentDocument) // For NS6
        obj = objIFrame.contentDocument.getElementById(idInIFrame);
    else if (objIFrame.contentWindow)   // For IE5.5 and IE6
        obj = objIFrame.contentWindow.document.getElementById(idInIFrame);
    else if (objIFrame.document)    // For IE5
        obj = objIFrame.document.getElementById(idInIFrame);
    return obj;
}

$().ready(function() {


	//会员
	<iterate name="selectUserGroupList" id="vo" key="k" >
		var selid = document.getElementById('user_group_id_'+{$vo.user_group_id});
		if (selid != null) {
			selid.checked = true;
		}
	</iterate>

	//子表
	if (document.getElementById('promoteChild') != null){
		<iterate name="promoteChildList" id="child" key="k" >
			newTr('{$child.module_name}', '{$child.rec_id}', '{$child.name}', '{$child.score}');
		</iterate>
	}

	//===================================================================================
	if ('{$module_name}' != ""){
		//alert('{$module_name}');
		var t = $('#selectbox div.jqmdMSG');	
		  $('#selectbox').jqm({
		    trigger: '#addChild',
		    target: t,
		    modal: true, /* FORCE FOCUS */
		    onHide: function(h) { 
			  if($("#is_close").val()==1)
			  {
				  var iframe_obj = document.getElementById("if_goods_list");
				  var iframe_doc = getElementByIdInIFrame(iframe_obj,"main");
				  var cbos = $(iframe_doc).find(".key");
				  var goods_ids = new Array();
				  for(var i=0;i<cbos.length;i++)
				  {
					if(cbos[i].checked)
					{
						goods_ids.push(parseInt(cbos[i].value));
					}
				  }
				  if(goods_ids.length>0)
				  {
				  	var ids = $.toJSON(goods_ids);
					$.ajax({
						  //type: "get",
						  //"{:u('Promote/getChildData', array('module_name'=>$module_name, 'ids'=>123))}"
						  url: "__APP__?m=Promote&a=getChildData&module_name={$module_name}&ids="+escape(ids),
						  success:function(data)
						  {
						  	//alert(data);
							data = $.evalJSON(data); 
							if ((data != "") && (data != null)){
								var obj = document.getElementsByName('rec_idList[]');
								for (var i=0;i<data.length;i++)
								{
									//检查是否已经在列表中，如果已经在列表中，则不需要再添加了
									for (var j=0;j<obj.length;j++)
									{
										if (obj[j].value == data[i].id)
									    {
											break;
										}
									}		
									//alert(result[i]);
									if (j >= obj.length)
									{
										newTr(data[i].module_name, data[i].id, data[i].name, data[i].score);
									}
								}			
							}
						  }
						});
				}	
			  }
			  else
			  {
				  $("#is_close").val(1);
			  }
		      h.o.remove(); // remove overlay
		      h.w.hide(100); // hide window	      
		    },
		    overlay: 10});
	}
	//===================================================================================    
});
var CLOSE = '{%CLOSE}';
</script>
<!-- 主页面结束 -->